// 分单公共方法
layui.define(['form', 'fms_util', 'layer', 'jquery', 'element'], function (exports) {

    var $ = layui.jquery,
        form = layui.form,
        fmsUtil = layui.fms_util,
        layerTips = parent.layer === undefined ? layui.layer : parent.layer,
        layer = layui.layer,
        element = layui.element;


    var util = {
        //日期
        getNowFormatDate: function (option) {
            var $input = option.input;
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + date.getMinutes()
                + seperator2 + date.getSeconds();
            $input.val(currentdate);
        },

        /**
         * 输入框搜索
         * @param options
         */
        searchMenu: function (options) {
            this.getMenuInformationById({
                platformType: options.platformType,
                callback: function (res) {
                    var $selector = options.selector;
                    /**
                     * 渲染控件
                     * @type {string}
                     */
                    var html = '<option value=""></option>';
                    $(res).each(function (i, data) {
                        if (data.menuId == null) {
                            html += '<option value="' + data.id + '">' + data.zhName + '</option>'
                        }
                    });
                    $selector.html(html);
                    $selector.each(function (k, obj) {
                        var $target = $(obj);
                        var selectVal = $target.attr("data");
                        if (selectVal !== undefined) {
                            $target.val(selectVal);
                        }
                    });
                    options.form.render("select");
                }
            });
        },
        searchBackstage: function (options) {
            this.getBackstageById({
                callback: function (res) {
                    var $selector = options.selector;
                    /**
                     * 渲染控件
                     * @type {string}
                     */
                    var html = '<option value=""></option>';
                    $(res).each(function (i, data) {
                        html += '<option value="' + data.enName + '">' + data.zhName + '</option>'
                    });
                    $selector.html(html);
                    $selector.each(function (k, obj) {
                        var $target = $(obj);
                        var selectVal = $target.attr("data");
                        if (selectVal !== undefined) {
                            $target.val(selectVal);
                        }
                    });
                    options.form.render("select");
                }
            });
        }
    };

    //公共数据
    var utilData = {
        getMenuInformationById: function (options) {
            fmsUtil.doAjax({
                action: "menuService.getMenu",
                data: {"platformType": options.platformType},
                load: false,
                type: 'get',//请求方式
                success: function (data) {
                    if (data.isSuccess == true) {
                        var dt = data.data;
                        /*arry.paush({id:dt.id,name:dt.name,remark:dt.remark});*/
                        options.callback(dt);
                    } else {
                        fmsUtil.msg(data.description);
                    }
                }
            });
            return options.callback;
        },
        getBackstageById: function (options) {
            fmsUtil.doAjax({
                action: "menuService.getPlatformType",
                data: {"systemSourceId": API.systemSourceId(), "pageSize": 1000},
                load: false,
                type: 'get',//请求方式
                success: function (data) {
                    if (data.isSuccess == true) {
                        var dt = data.data;
                        /*arry.paush({id:dt.id,name:dt.name,remark:dt.remark});*/
                        options.callback(dt);
                    } else {
                        fmsUtil.msg(data.description);
                    }
                }
            });
            return options.callback;
        }
    };

    var module = $.extend(util, utilData);

    exports('menu_common', module);
});